﻿CREATE FUNCTION QIC.[Split] (@String NVARCHAR(MAX), @Separator NVARCHAR(32))
RETURNS @Retval TABLE (String VARCHAR(MAX))   
AS
BEGIN
    DECLARE @xml XML
    SET @XML = N'<root><string>' + REPLACE(@String, @Separator, '</string><string>') + '</string></root>'

    INSERT INTO @Retval(String)
    SELECT string.value('.','NVARCHAR(MAX)') AS Item
    FROM @xml.nodes('//root/string') AS RECORDS(string)

    RETURN
END